package com.fmjava.service_upload.controller;

import com.fmjava.service_upload.service.UploadService;
import com.fmjava.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/*
 *@ClassName UploadController
 *@Description TODO
 *@Author 吃麻椒的花酱
 *@Date 2021/7/7 15:41
 *@Version 1.0
 */
@RequestMapping("/service_upload/file/")
@Api(tags = {"头像上传"})
@RestController
public class UploadController {
    @Autowired
    UploadService uploadService;

    @ApiOperation(value = "头像上传组件")
    @PostMapping("ossUploadFile")
    public ResponseResult uploadFile(@ApiParam(name = "file",value = "上传的头像图片" ,required = true) MultipartFile file){
        String url = uploadService.uploadFile(file);
        return ResponseResult.ok().data("url",url);
    }

    /*
     * @author 吃麻椒的花酱
     * @date  2021/7/10 1:54
     * @Description 接收什么样的参数，就应该使用什么样的注解，必须严格定义 以防止swagger测试文档报错，或者前端传值时出现错误
     * @param url
     * @return com.fmjava.utils.ResponseResult
     */
    @ApiOperation(value = "删除头像")
    @GetMapping("/deleteImage")
    public ResponseResult deleteFile(@ApiParam(name = "url", value = "删除图片路径",required = true) @RequestParam String url){
        uploadService.deleteFile(url);
        return ResponseResult.ok();
    }

}


